[QUOTE=tanthreecle;21056550]cannot find symbol[/QUOTE]
When someone gives you an example like "graphicsWindow.setSize(size)", the "graphicsWindow" variable is understood to be a placeholder for some suitable object in your program, that might or might not actually be named "graphicsWindow". If you'd asked how to add one to a variable, and someone told you "x += 1", you'd recognize that the "x" really just stands for some arbitrary int variable, and that you could actually write "foo += 1" or "bar += 1" to increment variables named "foo" and "bar". Examples like these are to be digested and understood by your brain, not just echoed from eyes back to keyboard character-for-character.
In the example you posted, it looks like you're trying to set the size of the main application window. I'm not familiar with the ACM classes, but [url=http://jtf.acm.org/javadoc/student/acm/program/GraphicsProgram.html]this Javadoc[/url] tells me that acm.program.GraphicsProgram extends acm.program.Program, which extends javax.swing.JApplet, which means that ACM programs are Swing applets and can use all the methods that are available for Swing applets. The ACM GraphicsProgram docs don't show all the methods inherited from JApplet and its superclasses, but if you click on one of those superclasses you'll get Sun's docs for them, which tells you that there's a setSize() method inherited from java.awt.Component. That's probably the one you want to call.
So, your Cannon class has a setSize() method that it inherits from Component. To call that method from within your run() method, you should be able to just write "setSize(800, 600)" since that's the normal way for a method to call another method on the same object. (Writing "this.setSize(800, 600)" would also work, but the former is shorthand for the latter.)
How can I play a sound in a C# Windows Form? I'm making it so if (Textbox1.Text != "55101") then it takes you to form2 and plays "C:\ChanceMachine\Sounds\Incorrect.wav". This is what I currently have for the button:
[cpp]
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "55904101");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
//Need code to play a sound D:
}
[/cpp]
Whatya got?
[url]http://lmgtfy.com/?q=C%23+play+sound[/url]
All those are telling me to make a file browser and stuff, but I don't need those. I just need to play a sound.
[QUOTE=efeX;21067047][url]http://lmgtfy.com/?q=C%23+play+sound[/url][/QUOTE]
your link miserably failed
[QUOTE=turb_;21067096]your link miserably failed[/QUOTE]
:v: oh well
[QUOTE=Chad Mobile;21067078]All those are telling me to make a file browser and stuff, but I don't need those. I just need to play a sound.[/QUOTE]
FUCKING HURR DURR WHAT THE FUCK IS THIS?
[img]http://imgkk.com/i/32zh.png[/img]
and you wonder why people don't like you
[QUOTE=Chad Mobile;21066997]How can I play a sound in a C# Windows Form? I'm making it so if (Textbox1.Text != "55101") then it takes you to form2 and plays "C:\ChanceMachine\Sounds\Incorrect.wav". This is what I currently have for the button:
[cpp]
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "55904101");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
//Need code to play a sound D:
}
[/cpp]
Whatya got?[/QUOTE]
[url=http://msdn.microsoft.com/en-us/library/system.media.soundplayer%28VS.80%29.aspx]SoundPlayer[/url].
[QUOTE=Chad Mobile;21066997]How can I play a sound in a C# Windows Form? I'm making it so if (Textbox1.Text != "55101") then it takes you to form2 and plays "C:\ChanceMachine\Sounds\Incorrect.wav". This is what I currently have for the button:
Whatya got?[/QUOTE]
[cpp]SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
simpleSound.Play();[/cpp]
Stolen from MSDN. It was the first link when I searched for "C# play sound"
[cpp]
System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
myPlayer.SoundLocation = @"C:\Key\Sound\wrong.wav";
myPlayer.Play();
[/cpp]
Got it on my own. Thanks.
No you didn't, voided did.
Say in C# i had a button on one form, Form1, and when that button was clicked, Form2 would show up
how would I do this?
[QUOTE=raccoon12;21068223]Say in C# i had a button on one form, Form1, and when that button was clicked, Form2 would show up
how would I do this?[/QUOTE]
[cpp]
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
[/cpp]
[editline]01:52AM[/editline]
[QUOTE=efeX;21068116]No you didn't, voided did.[/QUOTE]
I had the "post reply" box open for a while. :downs:
[QUOTE=Darwin226;21063659]So, I made a class in XNA, I have static variable spriteBatch and a static function init that takes SpriteBatch sb as an argument.
In Game1.cs I call the init function like Asdf.Init(spriteBatch) and the init function sets spriteBatch (the static var) to sb. I'm not sure but i think that it's only a reference. It might not matter tho.
Then I have a static method draw on my class that starts with spriteBatch.Begin() but it throws an exception Object reference not set to the instance of the object
I think is has something to do with the varibales and/or methods being static since almost the same thing works on another project that passes spriteBatch as an argument to the constructor when instancing that class.
Any ideas how I might fix this?
P.S. Are there special code tags for sharp highlighting?[/QUOTE]
Did you instantiate the SpriteBatch?
[QUOTE=Chad Mobile;21068376][cpp]
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
[/cpp][/QUOTE]
Oh wow, you delivered good help. I'm legitimately surprised
I'm trying to develop a shamir's secret sharing algorithm in C#, but for some reason trying to get the shares to combine is refusing to work for me. As far as I can tell, it SHOULD work, but whatever. Here's the full code.
[code]using System;
using System.IO;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
namespace Shamir
{
public class Share
{
public long X { get; private set; }
public BigInteger Y { get; private set; }
public Share(long x, BigInteger y)
{
X = x;
Y = y;
}
public Share(byte[] serialized)
{
using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(serialized)))
{
X = binaryReader.ReadInt64();
byte[] temp = new byte[binaryReader.ReadInt32()];
binaryReader.Read(temp, 0, temp.Length);
Y = new BigInteger(temp);
}
}
public byte[] Serialize()
{
byte[] temp;
using(MemoryStream memoryStream = new MemoryStream())
{
using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
{
binaryWriter.Write(X);
temp = Y.ToByteArray();
binaryWriter.Write(temp.Length);
binaryWriter.Write(temp);
temp = memoryStream.ToArray();
}
}
return temp;
}
public override string ToString()
{
return string.Format("secret({0})={1}", X, Y);
}
}
public class ShamirEngine
{
// Why do an internal class instead of just adding the methods? Because it makes it look a bit cleaner.
internal class PrivateData
{
public PrivateData(byte[] serialized)
{
try
{
byte[] temp;
MemoryStream memoryStream = new MemoryStream(serialized);
BinaryReader binaryReader = new BinaryReader(memoryStream);
Coefficients = new BigInteger[binaryReader.ReadInt32()];
for (int i = 0; i < Coefficients.Length; i++)
{
temp = new byte[binaryReader.ReadInt32()];
binaryReader.Read(temp, 0, temp.Length);
Coefficients[i] = new BigInteger(temp);
}
temp = new byte[binaryReader.ReadInt32()];
binaryReader.Read(temp, 0, temp.Length);
Q = new BigInteger(temp);
}
catch (Exception)
{
throw new InvalidDataException("Not a valid PrivateData struct.");
}
}
public PrivateData(BigInteger q, BigInteger[] coefficients)
{
Q = q;
Coefficients = coefficients;
}
public BigInteger[] Coefficients;
public BigInteger Q;
public BigInteger Poly(BigInteger X)
{
BigInteger Y = Coefficients[0];
for (int i = 1; i < Coefficients.Length; i++)
Y = Y.Add( Coefficients[i].Multiply(X.Pow(i)));
return Y.Mod(Q.Subtract(BigInteger.One));
}
public byte[] Serialize()
{
byte[] temp;
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write(Coefficients.Length);
for (int i = 0; i < Coefficients.Length; i++)
{
temp = Coefficients[i].ToByteArray();
binaryWriter.Write(temp.Length);
binaryWriter.Write(temp);
}
temp = memoryStream.ToArray();
return temp;
}
}
public static SecureRandom random = new SecureRandom();
public long K { get; private set; } // This is the threshold level. You need at LEAST this many keys to get the answer.
private PrivateData MyPrivateData;
public ShamirEngine(long k, int bits)
{
if (k < 2)
throw new InvalidParameterException("K needs to be at least 2.");
if(bits % 8 != 0)
throw new InvalidParameterException("Bits needs to be a multiple of 8.");
BigInteger Q = BigInteger.ProbablePrime(bits, random);
BigInteger[] coefficients = new BigInteger[k];
for (int i = 0; i < k; i++)
coefficients[i] = new BigInteger(bits-1,random);
MyPrivateData = new PrivateData(Q,coefficients);
}
public Share GetShare()
{
long x = random.NextLong();
if (x < 0)
x = -x;
return GetShare(x);
}
public Share GetShare(long x)
{
BigInteger y = MyPrivateData.Poly(BigInteger.ValueOf(x));
return new Share(x,y);
}
public byte[] GetSecret()
{
return MyPrivateData.Coefficients[0].ToByteArray();
}
public Share[] GetShares(int count)
{
Share[] Shares = new Share[count];
for (int i = 0; i < count; i++)
{
long x = i + 1;//random.Next(1,256); // random.NextLong(); // testing, wee!
if (x < 0)
x = -x; // Don't want no negative indexes here.
BigInteger y = MyPrivateData.Poly(BigInteger.ValueOf(x));
Shares[i] = new Share(x,y);
}
return Shares;
}
public BigInteger Q
{
get
{
return MyPrivateData.Q;
}
}
public static byte[] CombineShares(Share[] shares,BigInteger Q)
{
BigInteger secret = BigInteger.One;
for (int i = 0; i < shares.Length; i++)
{
double lambda = 1;
for (int j = 0; j < shares.Length; j++)
{
if (j != i)
{
lambda = lambda * (((double)(shares[j].X + 1)) / ((double)(shares[j].X - shares[i].X)));
}
}
secret = secret.Multiply(shares[i].Y.ModPow(BigInteger.ValueOf((long)lambda), Q)).Mod(Q);
}
return secret.ToByteArray(); // The idea behind this, by the way, is you can set it to use 256 bit keys, and Boom! There's a key for most ciphers.
}
}
}[/code]
Point out any dumb code, and of course if you manage to find the issue, praise be you.
Oh, and the Q thing. If you bother to look it up on wikipedia, it says nothing about it, but I've tried with and without and neither works. For me at least. I found some java one that I converted that uses it, and it works with it well, but it does all this dumb stuff with encrypting the shares with rsa, and then decrypting them, and... Well, it's a mess, and I don't want to use it. I also can't, since there's no real 'Generate a new key!' function, you need to make a whole new engine for it, and they didn't bother to think that they might need to serialize just the data to combine the shares, and I had to do tons of work just to get it to work at all... I'm going to stop there.
[editline]01:34AM[/editline]
Oh, and I know, I should be more consistent with the serialization. I'll refactor that after I get the thing working.
[QUOTE=Wyzard;21066274]When someone gives you an example like "graphicsWindow.setSize(size)", the "graphicsWindow" variable is understood to be a placeholder for some suitable object in your program, that might or might not actually be named "graphicsWindow". If you'd asked how to add one to a variable, and someone told you "x += 1", you'd recognize that the "x" really just stands for some arbitrary int variable, and that you could actually write "foo += 1" or "bar += 1" to increment variables named "foo" and "bar". Examples like these are to be digested and understood by your brain, not just echoed from eyes back to keyboard character-for-character.
In the example you posted, it looks like you're trying to set the size of the main application window. I'm not familiar with the ACM classes, but [url=http://jtf.acm.org/javadoc/student/acm/program/GraphicsProgram.html]this Javadoc[/url] tells me that acm.program.GraphicsProgram extends acm.program.Program, which extends javax.swing.JApplet, which means that ACM programs are Swing applets and can use all the methods that are available for Swing applets. The ACM GraphicsProgram docs don't show all the methods inherited from JApplet and its superclasses, but if you click on one of those superclasses you'll get Sun's docs for them, which tells you that there's a setSize() method inherited from java.awt.Component. That's probably the one you want to call.
So, your Cannon class has a setSize() method that it inherits from Component. To call that method from within your run() method, you should be able to just write "setSize(800, 600)" since that's the normal way for a method to call another method on the same object. (Writing "this.setSize(800, 600)" would also work, but the former is shorthand for the latter.)[/QUOTE]
Oh! It all makes sense now. Thanks a lot, dude.
[QUOTE=Ortzinator;21068542]Did you instantiate the SpriteBatch?[/QUOTE]
When I use spriteBatch.Draw() in Game1.cs it works fine and it's the same sapriteBatch I pass as the argument. I don't get what's wrong.
[QUOTE=turb_;21069955]Oh wow, you delivered good help. I'm legitimately surprised[/QUOTE]
me too
Okay so I have just started learning C++ and I'm trying to make the computer intelligently guess a number I put in. I've gotten this far and it can guess my number, but it's not doing it as intended.
Sometimes it will go too high, so it will go lower, but still too high, then it will go higher again, which is not supposed to happen. It's causing there to be a massive number of tries before it gets the number, say 200, where it would only take a human 10 tries maximum.
[cpp]
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int tries = 0, guess, number;
int main()
{
srand(time(0));
int guess = rand() % 100 + 1;
cout << "Type a number for the computer to progressively guess (100-1): ";
cin >> number;
do
{
if (guess > number)
cout << guess << " too high.\n";
tries++;
guess = rand() % guess + 1;
if (guess < number)
cout << guess << " too low.\n";
tries++;
guess = 100 - rand() % guess + 1;
} while (guess != number);
cout << "The computer guessed " << guess << endl;
cout << "The computer guessed your number in " << tries << endl;
}
[/cpp]
[QUOTE=The DooD;21077379]Okay so I have just started learning C++ and I'm trying to make the computer intelligently guess a number I put in. I've gotten this far and it can guess my number, but it's not doing it as intended.
Sometimes it will go too high, so it will go lower, but still too high, then it will go higher again, which is not supposed to happen. It's causing there to be a massive number of tries before it gets the number, say 200, where it would only take a human 10 tries maximum.
[cpp]
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int tries = 0, guess, number;
int main()
{
srand(time(0));
int guess = rand() % 100 + 1;
cout << "Type a number for the computer to progressively guess (100-1): ";
cin >> number;
do
{
if (guess > number)
cout << guess << " too high.\n";
tries++;
guess = rand() % guess + 1;
if (guess < number)
cout << guess << " too low.\n";
tries++;
guess = 100 - rand() % guess + 1;
} while (guess != number);
cout << "The computer guessed " << guess << endl;
cout << "The computer guessed your number in " << tries << endl;
}
[/cpp][/QUOTE]
I'm brushing up on my C++ as well, so I decided to do this
[cpp]
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int tries = 0, guess, number;
int main()
{
srand(time(0));
//minimum possible answer, maximum possible answer, number of possible answers
int floor=1, ceiling=100, range=100;
int guess = rand() % 100 + 1;
cout << "Type a number for the computer to progressively guess (100-1): ";
cin >> number;
do
{
if (guess > number) {
ceiling = guess - 1;
range = ceiling - floor;
cout << guess << " too high. Guess Range = " << floor << " to " << ceiling << "\n";
tries++;
guess = rand() % (range + 1) + floor;
}
else if (guess < number) {
floor = guess + 1;
range = ceiling - floor;
cout << guess << " too low. Guess Range = " << floor << " to " << ceiling << "\n";
tries++;
guess = rand() % (range + 1) + floor;
}
} while (guess != number);
cout << "The computer guessed " << guess << endl;
cout << "The computer guessed your number in " << tries << endl;
} [/cpp]
let me know if i fucked anything up. seems to be working perfectly
Ah wow yeah that's great.
[QUOTE=Darwin226;21076651]When I use spriteBatch.Draw() in Game1.cs it works fine and it's the same sapriteBatch I pass as the argument. I don't get what's wrong.[/QUOTE]
Could you post the code?
DisplayObject.cs
[cpp]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace GameEngine {
class DisplayObject {
public static GraphicsDevice graphicsDevice;
public static SpriteBatch spriteBatch;
Texture2D textura;
public Vector2 pos;
public float rotation;
public static List<DisplayObject> DisplayList=new List<DisplayObject>();
public DisplayObject(Texture2D atx) {
textura = atx;
}
public static void Init(GraphicsDevice agd, SpriteBatch asb){
graphicsDevice = agd;
spriteBatch = asb;
}
public static void draw(DisplayObject obj){
Trace.Write(spriteBatch);
spriteBatch.Begin();
spriteBatch.Draw(obj.textura,
obj.pos,
null,
Color.White,
obj.rotation,
new Vector2(obj.textura.Width / 2, obj.textura.Height / 2),
1f,
SpriteEffects.None,
0);
spriteBatch.End();
}
public static void drawAll() {
int i = 0;
while (i < DisplayList.Count) {
draw(DisplayList[i]);
}
}
}
}
[/cpp]
Game1.cs
[cpp]using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace GameEngine {
public class Game1 : Microsoft.Xna.Framework.Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1() {
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize() {
DisplayObject.Init(GraphicsDevice, spriteBatch);
base.Initialize();
}
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
Texture2D tempTx;
tempTx = Content.Load<Texture2D>("di");
DisplayObject temoObj = new DisplayObject(tempTx);
temoObj.pos = Vector2.Zero;
temoObj.rotation = 0f;
DisplayObject.DisplayList.Add(temoObj);
}
protected override void UnloadContent() {
}
protected override void Update(GameTime gameTime) {
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
DisplayObject.drawAll();
base.Draw(gameTime);
}
}
}
[/cpp]
There, please let me know if you have trouble reading it, I really want to get this solved.
[QUOTE=Metanoia;21078212]
let me know if i fucked anything up. seems to be working perfectly[/QUOTE]
I genuinely laughed my ass off when this happened:
[IMG]http://i48.photobucket.com/albums/f224/supadood111/lol.png[/IMG]
Ah that was my fault, I forgot to reset the variables when restarting the loop.
wtf. that's a divide by zero error. probably in the modulo operation for random guess generation
when you implemented the ability to try again, did you make it re-initialize the floor/ceiling/range variables?
edit:actually i can tell you didn't from the screenshot. that's the problem
Yes that was the problem. I realised when the floor was 49 straight away
[QUOTE=Darwin226;21078660]DisplayObject.cs
*snip*
There, please let me know if you have trouble reading it, I really want to get this solved.[/QUOTE]
I had a similar problem, and I think I solved it by creating the spritebatch in the intialize function.
Also, instead of using static variables, you should look into the GameComponent class and the IDrawable interface, and putting the SpriteBatch in the game's services (this.Services) and retrieving it from components, made my life a lot easier.
Services seem just the right thing. Thanks
[QUOTE=turb_;21069955]Oh wow, you delivered good help. I'm legitimately surprised[/QUOTE]
See, I know [B]how[/B] to help someone.
Sorry, you need to Log In to post a reply to this thread.