PDA

View Full Version : محاسبات ریاضی به یک صورت خاص



mortezagt
دوشنبه 29 اردیبهشت 1393, 22:40 عصر
سلام دوستان

کسی هست که بدونه چطور میشه محاسبه کرد که مثلا

یه تکس باکس داریم که عدد داخلش 0 هستش و یک تایمر .
میخوایم کاری کنیم که در طی مدت یک ساعت ، مثلا عدد 0 داخل تکس باکس بشه 1000 ولی توجه کنید که میخوام طوری باشه که طی این مدت یک ساعت، ( یک عدد یک عدد ) به تکس باکس اذافه بشه

دقیقا مثل بازی تراوین که تولید محصول در هر ساعت رو نشون میده و طی مدت این یک ساعت یک عدد یک عدد به منابعش اذافه میشه

خیلی فوریه اگه ممنکه راهنمایی کنید .

ممنون

mortezagt
دوشنبه 29 اردیبهشت 1393, 23:04 عصر
این کدی هست که محاسبات تولید منابع رو انجام میده مربوط به بازی ایکاریم
جاوا هستش
گفتم شاید بشه ازش الهام گرفت





if (timestamp > 0)
{
timestring = approx + timestring;
}
return timestring;
}

function simpleTimer(currentdate, interval)
{
if (!YAHOO.lang.isValue(currentdate))
{
currentdate = (new Date()).getTime() * 1000;
}
if (typeof interval == "undefined")
{
interval = 500;
}
var that = this;
this.serverTimeDiff = IKARIAM.time.serverTimeDiff;
this.currenttime = (new Date()).getTime() + this.serverTimeDiff;
this.tm;
this.createEvent("update", this);
this.updatefrequency = 1000;
this.ls = Math.floor(this.currenttime / this.updatefrequency);
this.onUpdate = function ()
{
this.currenttime = (new Date()).getTime() + this.serverTimeDiff;
if (this.ls != Math.floor(this.currenttime / this.updatefrequency))
{
this.ls = Math.floor(this.currenttime / this.updatefrequency);
this.fireEvent("update");
}
}
this.startTimer = function ()
{
this.tm = setTimeout (function ()
{
that.startTimer.call(that);
},
interval);
this.onUpdate();
};
this.stopTimer = function ()
{
this.tm = clearTimeout(this.iv);
};
}
YAHOO.augment(simpleTimer, YAHOO.util.EventProvider);

function getResourceCounter(config)
{
if (config.production == 0 && typeof config.spendings == "undefined")

return false;

if (typeof config.spendings == "undefined")
{
config.spendings = [];
}
var resCounter = new simpleTimer(config.currentdate, config.interval);
resCounter.startdate = config.startdate * 1000;
resCounter.production = config.production;
resCounter.limit = config.limit;
resCounter.spendings = config.spendings;
resCounter.startRes = config.available;
resCounter.currentRes = config.available;
resCounter.valueElem = Dom.get(config.valueElem);
resCounter.checkBounds = function ()
{
if (this.currentRes < this.limit[0])
this.currentRes = this.limit[0];
if (this.currentRes > this.limit[1])
this.currentRes = this.limit[1];
}
resCounter.subscribe("update", function ()
{
this.currentRes = this.startRes + this.production * Math.floor((this.currenttime - this.startdate) / 1000);
this.checkBounds();
for (var i = this.spendings.length - 1; i >= 0; --i)
{
this.currentRes = this.currentRes - this.spendings[i]['amount'] * Math.floor((this.currenttime - this.startdate) / 1000 / this.spendings[i]['tickInterval']) * this.spendings[i]['tickInterval'] / 3600;
}
this.checkBounds();

mortezagt
دوشنبه 29 اردیبهشت 1393, 23:27 عصر
این هم محاسبه منابع در بازی تراوین
فقط یکی اینا رو برای ما تجزیه و تحلیل کنه، خلاصه بشه
دمتون گرم

private function calculateProduction() {
global $technology,$database,$session;
$normalA = $database->getOwnArtefactInfoByType($_SESSION['wid'],4);
$largeA = $database->getOwnUniqueArtefactInfo($session->uid,4,2);
$uniqueA = $database->getOwnUniqueArtefactInfo($session->uid,4,3);
$upkeep = $technology->getUpkeep($this->unitall,0);
$heroData = $database->getHeroData($session->uid);
if($heroData['dead']==0 && $this->wid==$heroData['wref']){
$hwood = $heroData['r1'];
$hclay = $heroData['r2'];
$hiron = $heroData['r3'];
$hcrop = $heroData['r4'];
$hproduct = $heroData['r0'];
}

$this->production['wood'] = $this->getWoodProd()+$hwood+$hproduct;
$this->production['clay'] = $this->getClayProd()+$hclay+$hproduct;
$this->production['iron'] = $this->getIronProd()+$hiron+$hproduct;

if ($uniqueA['size']==3 && $uniqueA['owner']==$session->uid){
$this->production['crop'] = $this->getCropProd()-$this->pop-(($upkeep)-round($upkeep*0.50))+$hcrop+$hproduct;

}else if ($normalA['type']==4 && $normalA['size']==1 && $normalA['owner']==$session->uid){
$this->production['crop'] = $this->getCropProd()-$this->pop-(($upkeep)-round($upkeep*0.25))+$hcrop+$hproduct;

}else if ($largeA['size']==2 && $largeA['owner']==$session->uid){
$this->production['crop'] = $this->getCropProd()-$this->pop-(($upkeep)-round($upkeep*0.25))+$hcrop+$hproduct;

}else{
$this->production['crop'] = $this->getCropProd()-$this->pop-$upkeep+$hcrop+$hproduct;
}
}


private function processProduction() {
global $database;
$timepast = time() - $this->infoarray['lastupdate'];
$nwood = ($this->production['wood'] / 3600) * $timepast;
$nclay = ($this->production['clay'] / 3600) * $timepast;
$niron = ($this->production['iron'] / 3600) * $timepast;
$ncrop = ($this->production['crop'] / 3600) * $timepast;

$database->modifyResource($this->wid,$nwood,$nclay,$niron,$ncrop,1);
$database->updateVillage($this->wid);
$this->LoadTown();
}

private function getWoodProd() {
global $bid1,$bid5,$session;
$wood = $sawmill = 0;
$woodholder = array();
for($i=1;$i<=38;$i++) {
if($this->resarray['f'.$i.'t'] == 1) {
array_push($woodholder,'f'.$i);
}
if($this->resarray['f'.$i.'t'] == 5) {
$sawmill = $this->resarray['f'.$i];
}
}
for($i=0;$i<=count($woodholder)-1;$i++) { $wood+= $bid1[$this->resarray[$woodholder[$i]]]['prod']; }
if($sawmill >= 1) {
$wood += $wood /100 * $bid5[$sawmill]['attri'];
}
if($this->ocounter[0] != 0) {
$wood += $wood*0.25*$this->ocounter[0];
}
if($session->bonus1 == 1) {
$wood *= 1.25;
}
$wood += $wood*$this->ocounter[0]*0.25;
$wood *= SPEED;
return round($wood);
}

private function getClayProd() {
global $bid2,$bid6,$session;
$clay = $brick = 0;
$clayholder = array();
for($i=1;$i<=38;$i++) {
if($this->resarray['f'.$i.'t'] == 2) {
array_push($clayholder,'f'.$i);
}
if($this->resarray['f'.$i.'t'] == 6) {
$brick = $this->resarray['f'.$i];
}
}
for($i=0;$i<=count($clayholder)-1;$i++) { $clay+= $bid2[$this->resarray[$clayholder[$i]]]['prod']; }
if($brick >= 1) {
$clay += $clay /100 * $bid6[$brick]['attri'];
}
if($this->ocounter[1] != 0) {
$clay += $clay*0.25*$this->ocounter[1];
}
if($session->bonus2 == 1) {
$clay *= 1.25;
}
$clay += $clay*$this->ocounter[1]*0.25;
$clay *= SPEED;
return round($clay);
}

private function getIronProd() {
global $bid3,$bid7,$session;
$iron = $foundry = 0;
$ironholder = array();
for($i=1;$i<=38;$i++) {
if($this->resarray['f'.$i.'t'] == 3) {
array_push($ironholder,'f'.$i);
}
if($this->resarray['f'.$i.'t'] == 7) {
$foundry = $this->resarray['f'.$i];
}
}
for($i=0;$i<=count($ironholder)-1;$i++) { $iron+= $bid3[$this->resarray[$ironholder[$i]]]['prod']; }
if($foundry >= 1) {
$iron += $iron /100 * $bid7[$foundry]['attri'];
}
if($this->ocounter[2] != 0) {
$iron += $iron*0.25*$this->ocounter[2];
}
if($session->bonus3 == 1) {
$iron *= 1.25;
}
$iron += $iron*$this->ocounter[2]*0.25;
$iron *= SPEED;
return round($iron);
}

private function getCropProd() {
global $bid4,$bid8,$bid9,$session;
$crop = $grainmill = $bakery = 0;
$cropholder = array();
for($i=1;$i<=38;$i++) {
if($this->resarray['f'.$i.'t'] == 4) {
array_push($cropholder,'f'.$i);
}
if($this->resarray['f'.$i.'t'] == 8) {
$grainmill = $this->resarray['f'.$i];
}
if($this->resarray['f'.$i.'t'] == 9) {
$bakery = $this->resarray['f'.$i];
}
}
for($i=0;$i<=count($cropholder)-1;$i++) { $crop+= $bid4[$this->resarray[$cropholder[$i]]]['prod']; }
if($grainmill >= 1 || $bakery >= 1) {
$crop += $crop /100 * ($bid8[$grainmill]['attri'] + $bid9[$bakery]['attri']);
}
if($this->ocounter[3] != 0) {
$crop += $crop*0.25*$this->ocounter[3];
}
if($session->bonus4 == 1) {
$crop *= 1.25;
}
$crop += $crop*$this->ocounter[3]*0.25;
$crop *= SPEED;
return round($crop);
}

ali.rk
دوشنبه 29 اردیبهشت 1393, 23:49 عصر
ازتایمر استفاده کن . زمان( 1 ساعت )رو تقسیم بر تعداد کن بذار بعد از هر بار کارکرد یکی اضافه می کنه

aliagamon
دوشنبه 29 اردیبهشت 1393, 23:51 عصر
الان که میخوام بخوابم حال نداره کسی اینو بخونه ....:لبخند:
شما بیا از این استفاده کن اگه منظورتونو درست فهمیده باشم این باید درست کار کنه ...
Dim counter As Double = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
counter += 1000 / 3600
If 0 <> CInt(counter) Then
TextBox1.Text = (Convert.ToDouble(TextBox1.Text) + CInt(counter)).ToString
counter -= CInt(counter)
End If
If Convert.ToDouble(TextBox1.Text) >= 1000 Then
TextBox1.Text = "1000"
Timer1.Enabled = False
End If
End Sub
End Class
تایمر رو 1000 میلی ثانیه باشه ....(کامپایل نکردم ایشالله مشکلی بود باشه برا فردا )

mortezagt
سه شنبه 30 اردیبهشت 1393, 00:05 صبح
سلام برادر
یه نمونه برام میزاری؟

mortezagt
سه شنبه 30 اردیبهشت 1393, 00:17 صبح
ممنون از جوابت


از کجا مقدار تولید در هر ساعت رو میگیره ؟
فدات

mortezagt
سه شنبه 30 اردیبهشت 1393, 12:46 عصر
الان که میخوام بخوابم حال نداره کسی اینو بخونه ....:لبخند:
شما بیا از این استفاده کن اگه منظورتونو درست فهمیده باشم این باید درست کار کنه ...
Dim counter As Double = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
counter += 1000 / 3600
If 0 <> CInt(counter) Then
TextBox1.Text = (Convert.ToDouble(TextBox1.Text) + CInt(counter)).ToString
counter -= CInt(counter)
End If
If Convert.ToDouble(TextBox1.Text) >= 1000 Then
TextBox1.Text = "1000"
Timer1.Enabled = False
End If
End Sub
End Class
تایمر رو 1000 میلی ثانیه باشه ....(کامپایل نکردم ایشالله مشکلی بود باشه برا فردا )

اره درسته همینه
دمت گرم داداش حال دادی بخدا

mortezagt
سه شنبه 30 اردیبهشت 1393, 12:54 عصر
علی جان میشه کدی بزاری که اعداد اعشاری رو هم حساب کنه ؟

aliagamon
سه شنبه 30 اردیبهشت 1393, 13:04 عصر
مقدار تولید در ساعت که همون عدد 1000 هست ... منظورتون از اعشاریه چیه ؟ یعنی جای 1000 اعشاری باشه یا نه به صورت اعشاری اضافه کنه اگه اولی رو میگین که جای هزار عدد اعشاری بزارین ...
اگه دومی رو میگین که باید از این استفاده کنین (تازه اعشاری نشون بده اسون ترم میشه:لبخند:)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick TextBox1.Text = (Convert.ToDouble(TextBox1.Text) + 1000 / 3600).ToString
If Convert.ToDouble(TextBox1.Text) >= 1000 Then
TextBox1.Text = "1000"
Timer1.Enabled = False
End If
End Sub
End Class

mortezagt
سه شنبه 30 اردیبهشت 1393, 22:03 عصر
مقدار تولید در ساعت که همون عدد 1000 هست ... منظورتون از اعشاریه چیه ؟ یعنی جای 1000 اعشاری باشه یا نه به صورت اعشاری اضافه کنه اگه اولی رو میگین که جای هزار عدد اعشاری بزارین ...
اگه دومی رو میگین که باید از این استفاده کنین (تازه اعشاری نشون بده اسون ترم میشه:لبخند:)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick TextBox1.Text = (Convert.ToDouble(TextBox1.Text) + 1000 / 3600).ToString
If Convert.ToDouble(TextBox1.Text) >= 1000 Then
TextBox1.Text = "1000"
Timer1.Enabled = False
End If
End Sub
End Class

الان همین کد معادل جاواش چطور نوشته میشه داداش؟